/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function (s) {
  const stack = []
  const map = new Map()
  map.set('(', ')')
  map.set('[', ']')
  map.set('{', '}')
  for (let i = 0; i < s.length; i++) {
    if (map.has(s[i])) {
      stack.push(s[i])
    } else {
      let top = stack[stack.length - 1]
      if (map.get(top) == s[i]) {
        stack.pop()
      } else {
        return false
      }
    }
  }
  return stack.length == 0
};